const config = require('config');
const axios = require('axios');

/**
 * 调度运营
 */
class KingdeeOldIsv {

    /**
     * 构造器
     */
    constructor(params) {
        this.accessToken = params.access_token;
        this.groupName = params.groupName;
        this.accountId = params.accountId;
        this.domain = params.domain;
    }

    /**
     * 旧接口
     */
    async kingDeeOldIsv(data, params, kingDeeUrl, method) {
        let list;
        try {
            const api = 'https://api.kingdee.com' + kingDeeUrl +'?access_token=' + this.accessToken ;
            if (method === "POST") {
                const resp = await axios.post(api, data, {
                    headers: {
                        'Content-Type': 'application/json',
                        'groupName': this.groupName,
                        'accountId': this.accountId,
                        'X-GW-Router-Addr': this.domain
                    }
                });
                list = resp.data.data;
                if(resp.data.errorCode==="500"){
                    return  resp.data;
                }
            }
            if (method === "GET") {
                const resp = await axios.get(api, params, {
                    headers: {
                        'Content-Type': 'application/json',
                        'groupName': this.groupName,
                        'accountId': this.accountId,
                        'X-GW-Router-Addr': this.domain
                    }
                });
                list = resp.data.data;
            }
            return list;
        } catch (e) {
            console.error('调用接口', e);
            throw e;
        }
    }
}

module.exports = KingdeeOldIsv;
